#!/bin/sh
# Copyright (c) 2012, 2021, Oracle and/or its affiliates.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation.  The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

LOGFILE="$0.log"
echo "running test... output in file: `pwd`/$LOGFILE"
exec > "$LOGFILE"

# some build configs place binaries in subdirectories
BIN_DIR=${1:-"."}
echo "all binaries assumed in subdirectory \'$BIN_DIR\'"

# jvm
JAVA="@Java_JAVA_EXECUTABLE_PATH@"
JAVA_ARCH="@Java_JAVA_ARCH_OPT@"
JAVA_FLAGS="-ea -Xcheck:jni"

# this test
JAVA_CLASS="test.MyLoadUnloadTest"
UNLOAD_TEST_JAR="../jtie/test/unload/jtie-test-unload-@JAVA_NDB_VERSION@.jar"

# dependencies
NDBJTIE=".."
NDBCLIENT="../.."
NDBJTIE_JAR="$NDBJTIE/ndbjtie-@JAVA_NDB_VERSION@.jar"
NDBJTIE_TEST_JAR="ndbjtie-test-@JAVA_NDB_VERSION@.jar"
JAVA_CLASSPATH="-classpath $UNLOAD_TEST_JAR:$NDBJTIE_TEST_JAR:$NDBJTIE_JAR"
JAVA_LIBPATH="-Djava.library.path=$NDBCLIENT/$BIN_DIR"
JAVA_DEFS="-Dcom.mysql.jtie.test.MyLoadUnloadTest.target_package_prefixes=test.,com.mysql.ndbjtie. -Dcom.mysql.jtie.test.MyLoadUnloadTest.target_class_name=test.NdbJTieSmokeTest -Dcom.mysql.jtie.test.MyLoadUnloadTest.target_method_name=test"

TEST="
  $JAVA
  $JAVA_ARCH $JAVA_FLAGS
  $JAVA_CLASSPATH
  $JAVA_LIBPATH
  $JAVA_DEFS
  $JAVA_CLASS"

echo "running $TEST"
echo
$TEST
STATUS=$?
echo
echo "exit status: $STATUS"
exit "$STATUS"
